import '../../helper/uidata.dart';

import '../helper/dioHelper2.dart';

class DocSend {
  int ID;
  String Guid;
  String Title;
  String Content;
  int State;
  String FileSpaceId;
  String CreateTM;
  String UserId;
  String Members;
  String Remarks;

  DocSend(this.ID, this.Guid, this.Title, this.Content, this.State,
      this.FileSpaceId, this.CreateTM, this.UserId, this.Members, this.Remarks);
  DocSend.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        Title = json["Title"],
        Content = json["Content"],
        State = json["State"],
        FileSpaceId = json["FileSpaceId"],
        CreateTM = json["CreateTM"],
        UserId = json["UserId"],
        Members = json["Members"],
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'Title': Title,
        'Content': Content,
        'State': State,
        'FileSpaceId': FileSpaceId,
        'CreateTM': CreateTM,
        'UserId': UserId,
        'Members': Members,
        'Remarks': Remarks,
      };
  static Future<bool> Add(DocSend x1) async {
    var response = await DioHelper.Post("/DocSend/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(DocSend x1) async {
    var response = await DioHelper.Post("/DocSend/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(DocSend x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/DocSend/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<DocSend?> GetByID(int sID) async {
    var response =
        await DioHelper.Get("/DocSend/GetByID?ID=" + sID.toString(), {});

    if (response.statusCode == 200) return new DocSend.fromJson(response.data);
    return null;
  }

  static Future<List<DocSend>> GetList(
      int pageIndex, int pageSize, int state) async {
    var response = await DioHelper.Get(
        "/DocSend/GetList?p1=" +
            pageIndex.toString() +
            "&ps=" +
            pageSize.toString() +
            "&st=" +
            state.toString() +
            "&userID=" +
            UIData.CurrentUser!.Guid,
        {});

    var list1 = <DocSend>[];
    if (response.statusCode == 200) {
      //print(response.data);
      for (var x in response.data) {
        list1.add(new DocSend.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<DocSend>> GetAllList() async {
    var response = await DioHelper.Get("/DocSend/GetAllList", {});
    var list1 = <DocSend>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new DocSend.fromJson(x));
      }
    }
    return list1;
  }
}
